<template>
    <div class="app-container">
        <div v-if="!HotelBookAddVisible">
        <el-form :inline="true" class="demo-form-inline">
            <el-form-item>
                <el-input  v-model="searchObj.orderId" placeholder="订单ID"/>
            </el-form-item>
            <el-form-item>
                <el-input v-model="searchObj.zkcode" placeholder="酒店编号"/>
            </el-form-item>
            <el-form-item>
            <div class="block">
                    <span class="demonstration"></span>
                    <el-date-picker
                    v-model="searchObj.bookingTime"
                    align="left"
                    type="date"
                    value-format="yyyy-MM-dd hh:mm:ss"
                    placeholder="选择预约日期">
                    </el-date-picker>
            </div>
            </el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="getList()">查询</el-button>
            <el-button type="primary" icon="el-icon-search" @click="resetData()">重置</el-button>
        </el-form>
        
        <!-- 工具条 -->
        <div>
            <el-button type="danger" size="mini" @click="removeRows()">批量删除</el-button>
        </div>

        <!-- banner列表 -->
        <el-table :data="list" stripe style="width: 100%" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55"/>
            <el-table-column type="index" width="50" label="序号"/>
            <el-table-column prop="orderId" label="订单ID"/>
            <el-table-column prop="zkcode" label="酒店编号"/>
            <el-table-column prop="zkname" label="酒店名称"/>
            <el-table-column prop="bookingTime" label="预约时间" width="200"/>
            <el-table-column prop="roomcode" label="预约房间编号"/>
            <el-table-column prop="roomname" label="预约房间名称"/>
            <el-table-column prop="money" label="预约花销"/>
            <el-table-column prop="bookingInfo" label="预约详细信息"/>
            <el-table-column label="操作" width="320" align="center">
                <template slot-scope="scope">
                    <el-button type="danger" size="mini" 
                        icon="el-icon-delete" @click="removeDataById(scope.row.id)">删除</el-button>
                    <el-button type="primary" size="mini" icon="el-icon-edit" @click="handleClick(scope.row.id)">修改</el-button>
                </template>
            </el-table-column>
        </el-table>

        <!-- 分页 -->
        <el-pagination
        :current-page="current"
        :page-size="limit"
        :total="total"
        style="padding: 30px 0; text-align: center;"
        layout="total, prev, pager, next, jumper"
        @current-change="getList"
        />

        </div>

        <hotelbook-add v-if="HotelBookAddVisible" ref="HotelbookAdd"></hotelbook-add>
    </div>
</template>


<script>
import hotelbook from './api/hotelbook'
import HotelbookAdd from './hotelbookadd'

export default {
  data() {
    return {
        current:1,
        limit:3,
        searchObj:{},
        list:[],
        total:0,
        multipleSelection: [],
        HotelBookAddVisible: 0
    }
  },
  created() {
        
  },
  mounted(){
     this.getList();
  },
  activated: function(){
      this.HotelBookAddVisible = 0;
  },
  components:{
      HotelbookAdd
  },
  methods: {
    // 重置数据
    resetData(){
        this.searchObj.orderId='';
        this.searchObj.zkode='';
        this.searchObj.bookingTime='';
        this.getList(1);
    },
    // 跳转至修改界面
    handleClick(id){
        this.HotelBookAddVisible = 1;
        this.$nextTick(() => {
            this.$refs.HotelbookAdd.init(id);
        })
    },
    // 分页带条件查询酒店预约信息
    getList(page=1){
        this.current=page
        hotelbook.getHotelBookList(this.current,this.limit,this.searchObj)
        .then(({data}) =>{
            this.list = data.data.records;
            this.total = data.data.total;
        })  
    },
     // 删除酒店预约信息
    removeDataById(id) {
        this.$confirm('此操作将永久删除酒店预约信息, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
        }).then(() => { 
            hotelbook.deleteHotelBook(id)
                .then(response => {
                    this.$message({
                    type: 'success',
                    message: '删除成功!'
                })
                  this.getList(1)
                })
        })
    },
     // 批量删除酒店预约信息
    removeRows() {
        this.$confirm('此操作将永久删除酒店预约信息, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
        }).then(() => { 
            var idList = []
            for(var i=0;i<this.multipleSelection.length;i++) {
                var obj = this.multipleSelection[i]
                var id = obj.id
                idList.push(id)
            }
 
        hotelbook.batchRemoveHotelBook(idList)
            .then(response => {
                    this.$message({
                    type: 'success',
                    message: '删除成功!'
                    })
                this.getList(1)
            })
        })
    },
     // 当表格复选框选项发生变化的时候触发
    handleSelectionChange(selection) {
        this.multipleSelection = selection
    },
    
  }
}
</script>
